  var dc;
;(function($) {
  // Domain count

  var referentialMethods = {
    initReferential    : function() {
      $(".error").hide();
      // Pour faire joli
      $('.text-input').css({backgroundColor:"#FFFFFF", color:"#666666", width:"90%"});
      $('.text-input').focus(function(){
        $(this).css({backgroundColor:"#DCD8C3", color:"#FFFFFF", width:"90%"});
      });
      $('.text-input').blur(function(){
        $(this).css({backgroundColor:"#FFFFFF", color:"#666666", width:"90%", fontSize:"12px"});
      });
      // compte le nombre de domaines actuel
      var domains = $('#formEdit').children("fieldset[id^=domain_]");
      dc = domains.length;
      //alert(dc);
    },
    insertDomain       : function() {
      $(this).after('<fieldset id="domain_' + dc +'"></fieldset>');
      $("#domain_" + dc).html('<ol id="oldom_' + dc +'"></ol>');
      $("#oldom_" + dc).html('<li class="left"><label for="domain_title_'+dc+'">Titre</label><input id="domain_title_'+dc+'" name="domain_title_'+dc+'" class="text-input" type="text" /><label class="error" for="domain_title_'+dc+'" id="domain_title_error_'+dc+'">This field is required.</label></li>')
      .append('<li class="right"><label for="domain_description_'+dc+'">Description</label><textarea name="domain_description_'+dc+'" id="domain_description_'+dc+'" class="text-input" cols="65" rows="5"></textarea><label class="error" for="domain_description_'+dc+'" id="domain_description_'+dc+'_error">This field is required.</label></li>')
      .append('<li class="right"><label for="domain_help_'+dc+'">Aide</label><textarea name="domain_help_'+dc+'" id="domain_help_'+dc+'" class="text-input" cols="65" rows="5"></textarea></li>')
      .append('<li class="right"><input id="dom_1" class="submit" type="submit" value="OK" /></li>');
      $("#domain_" + dc).after('<a href="#" class="AddDomain" id="domain_add_'+dc+'">Add new domain</a>');
      $("#domain_add_"+dc).click(function(e) {
        $(this).prev().insertDomain();
      });
      $("#oldom_" + dc).after('<div class="right"><a href="#" class="AddCompetence">Add new competence</a></div>');
      this.initReferential();
    },

    insertCompetence     : function(n) {
      $(this).after('<fieldset id="domain_' + n +'"></fieldset>');
      $("#domain_" + n).html('<ol id="oldom_' + n +'"></ol>');
      $("#oldom_" + n).html('<li class="left"><label for="domain_title_'+n+'">Titre</label><input id="domain_title_'+n+'" name="domain_title_'+n+'" class="text-input" type="text" /><label class="error" for="domain_title_'+n+'" id="domain_title_error_'+n+'">This field is required.</label></li>')
      .append('<li class="right"><label for="domain_description_'+n+'">Description</label><textarea name="domain_description_'+n+'" id="domain_description_'+n+'" class="text-input" cols="65" rows="5"></textarea><label class="error" for="domain_description_'+n+'" id="domain_description_'+n+'_error">This field is required.</label></li>')
      .append('<li class="right"><label for="domain_help_'+n+'">Aide</label><textarea name="domain_help_'+n+'" id="domain_help_'+n+'" class="text-input" cols="65" rows="5"></textarea></li>')
      .append('<li class="right"><input id="dom_1" class="submit" type="submit" value="OK" /></li>');
      $("#domain_" + n).after('<a href="#" class="AddDomain">Add new domain</a>');
      $("#oldom_" + n).after('<div class="right"><a href="#" class="AddCompetence">Add new competence</a></div>');
    },
    /*deleteDomain : function() { ... }
    deleteCompetence     : function() { ... },
    validateDomain : function() { ... }
    validateCompetence     : function() { ... },
    validateMain : function() { ... }
    editDomain : function() { ... }
    editCompetence     : function() { ... },
    editMain : function() { ... }*/
  };
  $.each(referentialMethods, function(i) {
    $.fn[i] = this;
  });
})(jQuery);
